package fag.core.game.test.arkanoid;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import fag.core.geometry.Rectangle2D;
import fag.core.geometry.Vector2D;
import fag.core.model.Animation;
import fag.core.model.Frame;
import fag.core.model.Model;
import fag.core.model.SerializableImage;
import fag.core.model.Sprite;

public class BonusModel extends Model {
	
	private static final long serialVersionUID = -569917777592824051L;

	public BonusModel() {
		
		loadBonus("blue");
		loadBonus("brown");
		loadBonus("green");
		loadBonus("grey");
		loadBonus("purple");
		loadBonus("red");
		loadBonus("yellow");
	}
	
	private void loadBonus(String name) {
		
		Animation a = new Animation(name);
		for(int i = 1; i < 8; ++i) {
			a.addFrame(loadFrame(name, i));
		}
		getListAnimation().add(a);
		
	}
	
	private Frame loadFrame(String name, int i) {
		
		Frame f = new Frame(200);
		BufferedImage b = null;
		try {
			b = ImageIO.read(new File(System.getProperty("user.dir")+"/src/imgs/arkanoid/bonus/" + name + i + ".png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		Sprite s = new Sprite(new SerializableImage(b), new Vector2D());
		Rectangle2D hitbox = new Rectangle2D(0, 0, s.getWidth(), s.getHeight());
		
		f.setHitbox(hitbox);
		f.setSprite(s);
		f.updateBounds();
		
		return f;
	}
}
